package com.vhall.component.controller.account;


import com.alibaba.fastjson.JSONObject;
import com.vhall.component.controller.account.facade.UserFacade;
import com.vhall.component.entity.account.vo.AccessListVO;
import com.vhall.component.entity.account.vo.AccessTokenVO;
import com.vhall.component.framework.common.annotation.VhallComponent;
import com.vhall.component.plugin.common.annotation.TokenAuth;
import com.vhall.component.plugin.common.annotation.VssTokenAuth;
import com.vhall.component.plugin.common.support.Token;
import com.vhall.component.plugin.common.support.TokenThreadLocal;
import com.vhall.component.service.account.AccessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;

import java.util.List;

/**
 * 用户信息
 *
 * @author longzhen.gong
 * @date 2021/6/11 14:30
 */

@VhallComponent
public class UserController implements UserFacade {

    @Autowired
    private AccessService accessService;

    @Override
    @VssTokenAuth
    public List<Integer> getAccessList(@Validated AccessListVO reqVO) {
        return accessService.getAccessList(reqVO);
    }


    @Override
    @TokenAuth
    public JSONObject getAccessToken(@Validated AccessTokenVO reqVO) {
        Token token = TokenThreadLocal.getToken();
        return accessService.getAccessToken(token.getAccountId(), reqVO);
    }

    @Override
    @TokenAuth
    public JSONObject getVssToken() {
        Token token = TokenThreadLocal.getToken();
        return accessService.getVssToken(token.getAccountId());
    }

    @Override
    @TokenAuth("sys:paas:access")
    public JSONObject paasAccess(@Validated AccessTokenVO reqVO) {
        Token token = TokenThreadLocal.getToken();
        return accessService.getAccessToken(token.getAccountId(), reqVO);
    }
}
